﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Fierce.Core.Aop;
using Fierce.Entity.Basic;
using Fierce.MvcExtend.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Fierce.Mvc.Areas.Work.Controllers
{
    [Area("Work")]
    public class AuthorizeController : WorkController
    {
        [HttpGet]
        [AllowAnonymous]
        public IActionResult Login()
        {
            return View();
        }

        [HttpPost]
        [AllowAnonymous]
        public string Login(string username, string password)
        {
            var result = ServiceFactory.BasicUser.Login(username, password);

            if (result.Code == ServiceResultCode.Success)
            {
                SetLoginSession(result.Data as BasicUser);
            }

            return result.Serialize();
        }
    }
}